﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KardexSist.UserControls.Common;
using Kardex_Entity;
using Kardex_Common;
using Kardex_BussinesLogic;
using KardexSist.Library;

namespace KardexSist.UserControls.Supervisor
{
    public partial class CtrlMainSupervisor : CtrlMainBase, IOperations
    {
        private List<person> ListSupervisor;
        private IOperations IOperatioSingle;
        public CtrlMainSupervisor()
        {
            InitializeComponent();
            ctrlSupervisor1.MostrarListaClick +=  LoadGrid;
            IOperatioSingle = (IOperations)ctrlSupervisor1;  
        }

        private void LoadGrid()
        {
            try
            {
                SupervisorFactory d = new SupervisorFactory();
                ListSupervisor = d.GetListSupervisor();
                grdListManager.DataSource = ListSupervisor;
                FormatColumns();
            }
            catch (Exception ex)
            {
                Util.MessageBoxShow(Util.Enum_TypeMessage.ErrorExecption, ex);
            }
        }

        private void FormatColumns()
        {
            grvSupervisores.Columns["IdPerson"].Visible = false;
            grvSupervisores.Columns["centrodistribucion"].Visible = false;
            grvSupervisores.Columns["distribuidor"].Visible = false;
            grvSupervisores.Columns["lugarciexpedido"].Visible = false;
            grvSupervisores.Columns["client"].Visible = false;
            grvSupervisores.Columns["supervisor"].Visible = false;
            grvSupervisores.Columns["lugarciexpedido"].Visible = false;
            grvSupervisores.Columns["preventista"].Visible = false;
            grvSupervisores.Columns["supervisor"].Visible = false;
            grvSupervisores.Columns["IdTipoCIExpedido"].Visible = false;
            grvSupervisores.Columns["CI"].Visible = false;
            
            grvSupervisores.Columns["Name"].Caption = "Nombre";
            grvSupervisores.Columns["Name"].VisibleIndex = 0;
            
            grvSupervisores.Columns["IdCD"].Caption = "Centro Dist.";
            grvSupervisores.Columns["IdCD"].VisibleIndex = 3;

            grvSupervisores.Columns["Telephone"].Caption = "Telefono";
            grvSupervisores.Columns["Telephone"].VisibleIndex = 4;

        }
        public void Add()
        {
            IOperatioSingle.Add();
        }

        public void Delete()
        {
            IOperatioSingle.Delete();
        }

        public void Save()
        {
            IOperatioSingle.Save();
        }

        public void Export()
        {
            Utils.ExportGridView(grvSupervisores); 
        }

        private void grvSupervisores_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            try
            {
                object objSupervisor = grvSupervisores.GetFocusedRow();
            if (objSupervisor != null)
            {
                person personCurrent = new person() { supervisor = new supervisor() };
                var obj = (person)objSupervisor;
                personCurrent.IdCD = obj.IdCD;
                personCurrent.IdPerson = obj.IdPerson;                
                personCurrent.Name = obj.Name;
                personCurrent.Telephone = obj.Telephone;
                personCurrent.Activ = obj.Activ;                                
                personCurrent.supervisor.IdPerson = obj.IdPerson;
                 ctrlSupervisor1.TrigerObjPerson(personCurrent);
            } 
            }
            catch (Exception ex)
            {

                Util.MessageBoxShow(Util.Enum_TypeMessage.ErrorExecption, ex);
            }

        }
    }
}
